package com.cyy.aop;

        import org.aspectj.lang.ProceedingJoinPoint;
        import org.aspectj.lang.Signature;
        import org.aspectj.lang.annotation.*;
        import org.springframework.stereotype.Component;

/**
 * @author CYY
 * @since 2022/5/17
 */
@Component
@Aspect
public class MyAdvice {
    //定义切入点
    @Pointcut("execution(void com.cyy.dao.BookDao.update())")
    private void pt(){}

    @Pointcut("execution(int com.cyy.dao.BookDao.select())")
    private void pt2(){}

    //@Before("pt()")
    public void before(){
        System.out.println("before advice...");
    }

    //@After("pt()")
    public void after(){
        System.out.println("after advice...");
    }

    //@Around("pt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("around before advice...");
        //表示对原始操作的调用
        Object ret = pjp.proceed();
        System.out.println("around after advice...");
        return ret;
    }

    //@Around("pt2()")
    public Object aroundSelect(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("around before advice...");
        //表示对原始操作的调用
        Object ret = pjp.proceed();
        System.out.println("around after advice...");
        return ret;
    }

    //@AfterReturning("pt2()")
    public void afterReturning(){
        System.out.println("afterReturning advice...");
    }

    @AfterThrowing("pt2()")
    public void afterThrowing(){
        System.out.println("afterThrowing advice...");
    }

    /*public void around2(ProceedingJoinPoint pjp) throws Throwable {
        //获取执行签名信息
        Signature signature = pjp.getSignature();
        //通过签名获取执行类型（接口名）
        String className = signature.getDeclaringTypeName();
        //通过签名获取执行操作名称（方法名）
        String methodName = signature.getName();
        System.out.println(className);
        System.out.println(methodName);

        System.out.println("around before advice...");
        //表示对原始操作的调用
        Object ret = pjp.proceed();
        System.out.println("around after advice...");
    }*/
}